package logic

import (
	"car/carrpc/carrpc"
	"context"

	"car/api/internal/svc"
	"car/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CarAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCarAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CarAddLogic {
	return &CarAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CarAddLogic) CarAdd(req *types.CarAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	login, err := l.svcCtx.CarRpc.CarAdd(l.ctx, &carrpc.CarAddRequest{
		UserId:    req.UserId,
		ProductId: req.ProductId,
		Number:    req.Number,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    0,
		}, nil
	}
	return &types.Response{
		Message: "添加购物车成功",
		Data:    login,
		Code:    200,
	}, nil

}
